package com.wnhz.work.jy.activity;

import android.app.Activity;
import android.content.Intent;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.util.Log;
import android.view.View;

import com.wnhz.work.jy.BaseActivity;
import com.wnhz.work.jy.R;
import com.wnhz.work.jy.adapter.ArrayWheelAdapter;
import com.wnhz.work.jy.utils.OnWheelChangedListener;
import com.wnhz.work.jy.view.WheelView;

import java.util.List;

/**
 * 选择银行
 */
public class SetBankActivity extends Activity implements OnWheelChangedListener, View.OnClickListener {
    private WheelView id_bank;
    protected String[] banks;
    private List<String> list;
    private int index = 0;
    private static final String TAG = "SetBankActivity";

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_set_bank);
        id_bank = (WheelView) findViewById(R.id.id_bank);
        id_bank.addChangingListener(this);
        findViewById(R.id.layout_updateBirth_root).setOnClickListener(this);
        list = (List<String>) getIntent().getSerializableExtra("list");
        banks = new String[list.size()];
        for (int i = 0; i < list.size(); i++) {
            banks[i] = list.get(i);
        }
        id_bank.setViewAdapter(new ArrayWheelAdapter<String>(
                SetBankActivity.this, banks));
        // 设置可见条目数量

        id_bank.setVisibleItems(7);
        findViewById(R.id.btn_choose_ok).setOnClickListener(new View.OnClickListener() {

            @Override
            public void onClick(View v) {
                // TODO Auto-generated method stub
                Intent intent = new Intent();
                intent.putExtra("bank_name", bank_name);
                intent.putExtra("index", index);
                setResult(RESULT_OK, intent);
                finish();
            }
        });
        findViewById(R.id.btn_choose_cancel).setOnClickListener(new View.OnClickListener() {

            @Override
            public void onClick(View v) {
                // TODO Auto-generated method stub
                finish();
            }
        });
        if (banks.length > 0){
            bank_name = banks[index];
            Log.e(TAG, "onCreate: "+bank_name );
        }

    }

    String bank_name;
    @Override
    public void onChanged(WheelView wheel, int oldValue, int newValue) {
        index = id_bank.getCurrentItem();

        bank_name = banks[index];
    }

    @Override
    public void finish() {
        // TODO Auto-generated method stub

        super.finish();
        overridePendingTransition(R.anim.push_up_in, R.anim.push_up_out);
    }

    @Override
    public void onClick(View view) {
        switch (view.getId()){
            case R.id.layout_updateBirth_root:
                finish();
                break;
        }
    }
}
